package main

import "flag"
//import "strings"
import "log"
//import "fmt"
import "time"
import "demoutil"

// Distributed System
import "shardmaster"

//go build shardmaster_server.go
//./shardmaster_server -port=9001 -peers=machine2:9001,machine3:9001

// using tcp for simplicity

var Port = flag.String("port", "0", "port number")
var Peers = flag.String("peers", "", "port number")

var sma *shardmaster.ShardMaster

func main() {
	flag.Parse()
	if *Port == "0" {
		log.Fatal("need a port number ")
	}

	servers := demoutil.ParseAddresses(*Peers)
	servers = append(servers, ":" + *Port)
	me := len(servers) - 1
	sma = shardmaster.StartServer(servers, me)
	sma.SetTag("sm_")
	for sma.Alive() {
		time.Sleep(100*time.Second)
	}
}

